﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Events;
using IdentityServer4.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Authorization.Application;
using Authorization.Entitys.DTO;
using Authorization.Infrastructure;

namespace Vue.H5.Authorization.Controllers
{
    public class AccountController : Controller
    {
        private readonly AccountApps accountApp;


        public AccountController(AccountApps _accountApp)
        {
            accountApp = _accountApp;
        }
        /// <summary>
        /// 登录页面
        /// </summary>
        /// <param name="ReturnUrl"></param>
        /// <returns></returns>
        [Route("oauth2/authorize")]
        [HttpGet]
        public IActionResult Login(string ReturnUrl)
        {
            return View();
        }
        [Route("login")]
        [HttpPost]
        public async Task<NarutoResult> LoginIn([FromBody] LoginDTO info)
        {
            return await accountApp.Login(info);
        }
        [Route("/consent")]
        public async Task Consent()
        {
        }
        [Route("/accessdenied")]
        /// <summary>
        /// 授权拒绝的页面
        /// </summary>
        /// <returns></returns>
        public async Task AccessDenied()
        {
        }
        [Route("/loginout")]
        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> LoginOut(string redirectUrl)
        {
            await accountApp.LoginOut();
            //清理cookie
            Response.Cookies.Delete(ConstObject.LoginCookieToken);
            //跳转地址
            ViewBag.redirectUrl = redirectUrl;
            return View();
        }
    }
}
